<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActiveSupport::Cache::MemCacheStore</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActiveSupport::Cache::MemCacheStore</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/rails/activesupport/lib/active_support/cache/mem_cache_store_rb.html">
                vendor/rails/activesupport/lib/active_support/cache/mem_cache_store.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="Store.html">
                Store
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
A cache store implementation which stores data in Memcached: <a
href="http://www.danga.com/memcached">www.danga.com/memcached</a>/
</p>
<p>
This is currently the most popular cache store for production websites.
</p>
<p>
Special features:
</p>
<ul>
<li>Clustering and load balancing. One can specify multiple memcached servers,
and <a href="MemCacheStore.html">MemCacheStore</a> will load balance
between all available servers. If a server goes down, then <a
href="MemCacheStore.html">MemCacheStore</a> will ignore it until it goes
back online.

</li>
<li>Time-based expiry support. See <a
href="MemCacheStore.html#M000330">write</a> and the +:expires_in+ option.

</li>
</ul>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000331">clear</a>&nbsp;&nbsp;
      <a href="#M000329">new</a>&nbsp;&nbsp;
      <a href="#M000332">stats</a>&nbsp;&nbsp;
      <a href="#M000330">write</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">addresses</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000329" class="method-detail">
        <a name="M000329"></a>

        <div class="method-heading">
          <a href="#M000329" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(*addresses)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a <a href="MemCacheStore.html#M000329">new</a> <a
href="MemCacheStore.html">MemCacheStore</a> object, with the given
memcached server addresses. Each address is either a host name, or a
host-with-port string in the form of &quot;host_name:port&quot;. For
example:
</p>
<pre>
  ActiveSupport::Cache::MemCacheStore.new(&quot;localhost&quot;, &quot;server-downstairs.localnetwork:8229&quot;)
</pre>
<p>
If no addresses are specified, then <a
href="MemCacheStore.html">MemCacheStore</a> will connect to localhost port
11211 (the default memcached port).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000329-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000329-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/cache/mem_cache_store.rb, line 35</span>
35:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">addresses</span>)
36:         <span class="ruby-identifier">addresses</span> = <span class="ruby-identifier">addresses</span>.<span class="ruby-identifier">flatten</span>
37:         <span class="ruby-identifier">options</span> = <span class="ruby-identifier">addresses</span>.<span class="ruby-identifier">extract_options!</span>
38:         <span class="ruby-identifier">addresses</span> = [<span class="ruby-value str">&quot;localhost&quot;</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">addresses</span>.<span class="ruby-identifier">empty?</span>
39:         <span class="ruby-ivar">@addresses</span> = <span class="ruby-identifier">addresses</span>
40:         <span class="ruby-ivar">@data</span> = <span class="ruby-constant">MemCache</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">addresses</span>, <span class="ruby-identifier">options</span>)
41:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000331" class="method-detail">
        <a name="M000331"></a>

        <div class="method-heading">
          <a href="#M000331" class="method-signature">
          <span class="method-name">clear</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000331-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000331-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/cache/mem_cache_store.rb, line 109</span>
109:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear</span>
110:         <span class="ruby-ivar">@data</span>.<span class="ruby-identifier">flush_all</span>
111:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000332" class="method-detail">
        <a name="M000332"></a>

        <div class="method-heading">
          <a href="#M000332" class="method-signature">
          <span class="method-name">stats</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000332-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000332-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/cache/mem_cache_store.rb, line 113</span>
113:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stats</span>
114:         <span class="ruby-ivar">@data</span>.<span class="ruby-identifier">stats</span>
115:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000330" class="method-detail">
        <a name="M000330"></a>

        <div class="method-heading">
          <a href="#M000330" class="method-signature">
          <span class="method-name">write</span><span class="method-args">(key, value, options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Writes a value to the cache.
</p>
<p>
Possible options:
</p>
<ul>
<li>+:unless_exist+ - set to true if you don&#8216;t want to update the cache
if the key is already set.

</li>
<li>+:expires_in+ - the number of seconds that this value may stay in the
cache. See <a
href="Store.html#M000336">ActiveSupport::Cache::Store#write</a> for an
example.

</li>
</ul>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000330-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000330-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/cache/mem_cache_store.rb, line 58</span>
58:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">write</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">nil</span>)
59:         <span class="ruby-keyword kw">super</span>
60:         <span class="ruby-identifier">method</span> = <span class="ruby-identifier">options</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:unless_exist</span>] <span class="ruby-operator">?</span> <span class="ruby-identifier">:add</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">:set</span>
61:         <span class="ruby-comment cmt"># memcache-client will break the connection if you send it an integer</span>
62:         <span class="ruby-comment cmt"># in raw mode, so we convert it to a string to be sure it continues working.</span>
63:         <span class="ruby-identifier">value</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">raw?</span>(<span class="ruby-identifier">options</span>)
64:         <span class="ruby-identifier">response</span> = <span class="ruby-ivar">@data</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">expires_in</span>(<span class="ruby-identifier">options</span>), <span class="ruby-identifier">raw?</span>(<span class="ruby-identifier">options</span>))
65:         <span class="ruby-identifier">response</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Response</span><span class="ruby-operator">::</span><span class="ruby-constant">STORED</span>
66:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">MemCache</span><span class="ruby-operator">::</span><span class="ruby-constant">MemCacheError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
67:         <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">error</span>(<span class="ruby-node">&quot;MemCacheError (#{e}): #{e.message}&quot;</span>)
68:         <span class="ruby-keyword kw">false</span>
69:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>